Modbus TCP/IP Overview

The Automation1 controller supports the Modbus TCP/IP Industrial Ethernet protocol. Modbus TCP/IP is an extension of the Modbus family of vendor-neutral communication protocols used for supervision and control of automation equipment. Specifically, it provides a network and transport layer in an Internet environment over the TCP/IP protocols for the Modbus application layer. The most common use of the protocol is for communication with Ethernet-based PLCs, I/O modules, and other simple field buses or I/O networks. The Modbus TCP/IP protocol is an automation standard.

The TCP/IP stack of Modbus connects over port 502, and it does not require a checksum as the lower protocol layers already provide checksum protection. The Modbus application layer data consists of the information in the table that follows.

Table: Modbus Application Layer Data

Memory Block Automation1 Register Data Type Client Access Server Access
Coils Output Bits Boolean Read/Write Read-Only
Discrete Inputs Input Bits Boolean Read-only Read/Write
Holding Registers Output Words 16-Bit Unsigned Integer Read/Write Read-Only
Input Registers Input Words 16-Bit Unsigned Integer Read-only Read/Write

Licensing

The Controller Plus (-CP) licensing option supports the Modbus stacks that follow on the controller:

-CP0

  • 1 Modbus Server

  • 1 Modbus Client

-CP1

  • 1 Modbus Server

  • 16 Modbus Clients

Networking

Automation1 supports Modbus TCP/IP Client and Server on both PC and drive-based controllers. The supporting hardware is different for the different controller types.

Drive-Based Controllers

Automation1 supports real-time networking capabilities with the Modbus TCP/IP protocol on drive-based controllers through the onboard Industrial Ethernet network interface. The drive-based controller network interface has two Industrial Ethernet ports labeled A and B. For Modbus, only port A is available for communication.

PC Controllers

Automation1 supports real-time networking capabilities with the Modbus TCP/IP protocols on the PC-controller through a dedicated PCIe network interface card (NIC).

IMPORTANT: Modern PC motherboards can have two NICs. Usually, one of the NICs can be used by INtime to support Industrial Ethernet communication.

Supported families of network cards:

  • Broadcom Gigabit (bge1g.rsl)

  • Intel 10/100Mbps (ie100m.rsl)

  • Intel Gigabit (ie1g.rsl)

  • RealTek 10/100 Mbps (rtl100m.rsl)

  • RealTek Gigabit (rtl1g.rsl)

See the Compatible Network Interface Cards section for individual device information.

Installation

Automation1 NICs for Modbus are passed to INtime in the same manner as the HyperWire card. After installing a standalone PCIe NIC or just utilizing a secondary, dedicated motherboard NIC, do the procedure that follows to pass the card to INtime control:

  1. Open INtime Device Manager. (Start > All Programs > INtime > INtime Configuration. Then double-click INtime Device Manager).

  2. In the Windows devices tree, find your network adapter. Right-click your adapter and select Pass to INtime using MSI.

  3. Click File and then select Save the Configuration. The card will now be listed under the INtime devices tree.

  4. Close INtime Device Manager.

IP Configuration

Use the Automation1 Studio to configure the applicable device driver for your network interface and to configure the IP networking information. To manage the IP networking information, click the Edit button on the Industrial Ethernet tab. For more information about this tab, see the Industrial Ethernet Tab section of the Variables & I/O module in the Develop workspace. In the Industrial Ethernet: Edit dialog, click the Configure Network Interface button in the bottom left corner.

In the Configure Network Interface window, you can select the applicable driver for your NIC and enter the IP networking information. The IP Address, Subnet Mask, and Gateway are all required. To use DHCP, click the Automatically assign IP address using DHCP server toggle. To clear the NIC configuration, click the Clear Configuration button in the bottom left corner.

Create a Modbus Connection

You must create a connection to enable the Modbus Client or Server on the controller. To manage the current connections, click the Edit button on the Industrial Ethernet tab. For more information about this tab, see the Industrial Ethernet Tab section of the Variables & I/O module in the Develop workspace. In the Industrial Ethernet: Edit dialog, you can see the current connections, and you can add a new connection when you click the + Connection button. The information that you must use to create a connection is different for Modbus Client and Modbus Server.

Required Modbus Server Information

  • Name – The name of Modbus Server. This name is informational only and is used to differentiate between Modbus Server connections within Automation1.

  • ID – The Unit ID of the Modbus Server. This value is used by the Modbus protocol to differentiate between multiple Modbus Servers that are operating at the same IP address.

Required Modbus Client Information

  • Name – The name of Modbus Client. This name is informational only and is used to differentiate between Modbus Client connections within Automation1.

  • ID – The Unit ID of the Modbus Server being connected to. This value is used by the Modbus protocol to differentiate between multiple Modbus Servers that are operating at the same IP address.

  • IP Address – The IP address of the Modbus Server being connected to.

  • Port – The port of the Modbus Server being connected to.

When you configure Automation1 as a Modbus Server, the Modbus Server is configured to use port 502.

After you supply the required information, click Add to save the connection. You can now add variable mappings to the connection as described in the next section.

Configuration

Automation1 exposes the function codes of Modbus through a concept of Industrial Ethernet mappings. These Industrial Ethernet mappings let you map the memory regions of Modbus to arbitrary controller data types that you can access with the function codes. You can configure the registers that follow on the Modbus Client and Modbus Server:

Table: General Modbus Function Code Mapping

Function Code Modbus Variable Access

FC 1(0x01)

Read Output Bit

FC 2 (0x02)

Read Input Bit

FC 3 (0x03)

Read Output Word

FC 4 (0x04)

Read Input Word

FC 15 (0x0F)

Write Output Bits

FC 16 (0x10)

Write Output Words

When you configure the controller as a Modbus Server, it will also respond to the function codes that follow:

Table: Modbus Server Function Code Mapping

Function Code Modbus Variable Access

FC 5 (0x05)

Write Output Bit

FC 6 (0x06)

Write Output Word

FC 22 (0x16)

Masked Write Output Word

FC 23 (0x17)

Read/Write Output Word

Each Industrial Ethernet mapping supports the fields that follow:

  • Name

    • The name of the variable. This name will be automatically converted into an AeroScript variable by the controller that can be interacted with via programs or libraries.

  • Count

    • Determines how many contiguous sequences there will be of this variable. With counts greater than 1, the controller accesses the variables like an array. You can access the variables through an Industrial Ethernet mapping array.

  • Type

    • Lets you configure the Modbus registers as different data types. The data types that follow are supported.

    • Table: Supported Data Types

      Data Type Description
      Bit 1-bit Boolean value
      UInt8 8-bit unsigned integer
      UInt16 16-bit unsigned integer
      UInt32 32-bit unsigned integer
      Int8 8-bit signed integer
      Int16 16-bit signed integer
      Int32 32-bit signed integer
      Float32 32-bit single-precision floating-point value
      Float64 64-bit double-precision floating-point value

  • Byte Address

    • Configures the byte offset of the register.

  • Bit Address

    • Configures the bit offset of the register.

    • The final address is the sum of byteAddress * 8 + bitAddress.

    • Non-bit data types must be 8-bit byte aligned

  • Comment

    • Can be used to provide some information about the mapping.

Use Automation1 Studio to configure the Modbus mappings. For information about how to configure Industrial Ethernet mappings from the UI of the application, see the related procedures in the Industrial Ethernet Tab section of the Variables & I/O module in the Develop workspace.

Detecting a Disconnected Modbus Server

Modbus communication is always started by the Modbus Client. Thus it is not possible for the Automation1 controller to detect a disconnected Modbus Server without continuously reading or writing the variables of that server. If it is important for you to detect a disconnected Modbus Server, you must start a write or read from the Modbus Client at regular intervals. If you are not writing output mappings from the Modbus Client, you can make an input mapping (InputWord or InputBit) and regularly read from it. This will create the network traffic that is necessary so you can detect a disconnected server.

AeroScript

After you configure the mappings, the controller automatically converts the names of the Modbus variables into AeroScript properties that can be directly interacted with. The code sample that follows shows an example of the properties that would be generated from an example mapping.

Register Name Count Type Byte Address Bit Address
InputWords MyInteger 1 UInt16 0 0
OutputWords MyReal 4 Float64 8 0

Code Sample

property $MyInteger as integer
property $MyReal[$index as integer] as real

Status Items / Data Collection

Automation1 supplies many Modbus status items that you can use directly or through Data Collection. All of the Modbus status items are in the System category. You can access the Modbus status items with the StatusGetSystemItem() function. You can add the Modbus status items to Data Collection with the DataCollectionAddSystemSignal() function.

To get status information for the client and the server configurations, use the status items that follow.

  • Modbus Client Connected

  • Modbus Client Error

  • Modbus Server Connected

  • Modbus Server Error

To access the data that is sent over the Modbus connection, use the status items that follow.

  • Modbus Client Input Words
  • Modbus Client Input Bits

  • Modbus Client Input Words Status

  • Modbus Client Output Words

  • Modbus Client Output Bits

  • Modbus Client Output Words Status

  • Modbus Server Input Words

  • Modbus Server Input Bits

  • Modbus Server Output Words

  • Modbus Server Output Bits

The Modbus data status items must have one more data field to specify the connection index, data type, byte offset, and bit offset. To determine the correct additional data value, refer to the computeModbusAdditionalData() AeroScript example function that follows. If you want to use this function, you must add the code to your AeroScript program.

  • $Index – The index of the connection as defined in Automation1. The first created connection is index 0. To see the currently defined connections, go to the Variables & I/O module of the Develop workspace and open the Industrial Ethernet tab. For more information about this tab, see Industrial Ethernet Tab.
  • $DataType – The type of the data.
  • $BitOffset – The bit offset of the data item as defined in the Modbus mapping.
  • $ByteOffset – The byte offset of the data item as defined in the Modbus mapping.
function computeModbusAdditionalData($Index as integer, $DataType as ModbusRegisterDataType, $BitOffset as integer, $ByteOffset as integer) as integer
    var $additionalData as integer

    $additionalData = ($Index << 28) & 0xF0000000 | ($DataType << 23) & 0x0F800000 | ($BitOffset << 20) & 0x00700000 | ($ByteOffset & 0x000FFFFF)

    return $additionalData
end

program
	$iglobal[0] = computeModbusAdditionalData(0, ModbusRegisterDataType.Float64, 0, 256)
end

Troubleshooting

If you cannot make a connection between Automation1 and your Modbus device, try the troubleshooting steps that follow.

  1. If you are using a PC controller, make sure that you selected the correct driver for your network card as listed in the Compatible Network Interface Cards section.

  2. If you are using a PC controller, make sure that your network card is passed to INtime in the INtime Device Manager. See the Installation section on this page.

  3. Use the Status Utility to make sure that the network information you entered is correct. The Ethernet tab shows the Industrial Ethernet Network information.

  4. Industrial Ethernet Network Item Description
    IP Address The IP address of the Industrial Ethernet Network.
    Subnet Mask The Subnet Mask of the Industrial Ethernet Network.
    Gateway The Default Gateway of the Industrial Ethernet Network.
    MTU The MTU size of the Industrial Ethernet Network.
    Estimated Link Speed The estimated speed of the link layer of the Industrial Ethernet Network in Mbps.
  5. Use the Status Utility to make sure that a Modbus Client or Server is configured and running. The Ethernet tab shows the Modbus information.

  6. Modbus Item Description
    Client Enabled Mask Shows which Modbus Clients are configured in the aeroscriptmappings file.
    Client Connected Mask Shows which Modbus Clients have an active Modbus connection.
    Client 0 Error Shows the active error on the first Modbus Client, if any.
    Client 1 Error Shows the active error on the second Modbus Client, if any.
    Server Enabled Shows if the Modbus Server is configured in the aeroscriptmappings file.
    Server Connected Shows if the Modbus Server has an active Modbus connection.
    Server Error Shows the active error on the Modbus Server, if any.
  7. If you are using a PC controller, try to ping your network card and the Modbus device you are trying to connect with through the INtime ping utility. Use the INtime RT Application Loader to run the ping.rta binary in the network7 folder.

    1. You can ping the address of your network card to confirm INtime can communicate with the card.

    2. You can ping the address of the Modbus device you are trying to connect with in order to confirm that the destination IP address is reachable by the Automation1 PC.

  8. If you are unable to ping your device, confirm there is not a firewall preventing traffic between the two devices. If you are using a firewall, you will have to add an exception for the port on which you configured Modbus.

Compatible Network Interface Cards

The NIC devices that follow are supported by INtime for use with Modbus on the PC-based Automation1 controller. Select the drop-down based on the version of INtime installed on your PC.

Select INtime 7.0.23244.1 if you originally installed Automation1 2.7 or newer on your PC.

Select INtime 6.4.19245.2 if you originally installed Automation1 2.6 or older on your PC.